package mulMan;

import java.util.ArrayList;
import java.util.List;
import mulMan.domain.AudioFile;
import mulMan.domain.Library;
import mulMan.gui.controller.LibraryController;
import mulMan.gui.view.LibraryView;
import mulMan.services.AudioFileServices;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		ApplicationContext context = new ClassPathXmlApplicationContext(
				"application-context.xml");
		
		AudioFileServices audioFileServices = (AudioFileServices) context.getBean("audioFileServices");
		
		//We create the Library Model and fill it from the database
		Library library = new Library();
		List<AudioFile> libraryList = new ArrayList<AudioFile>();
		
		try {
			libraryList = audioFileServices.getAudioFiles();
		} catch (Exception e) {
			e.printStackTrace();
		}
		if (libraryList != null) {
			library.clear();
			for (int i=0; i<libraryList.size(); i++) {
				library.addElement(libraryList.get(i));
			}
		}
		
		//We create the View
		LibraryView view = new LibraryView(library);
		
		//We create the Controller
		new LibraryController(library, view);
	}
}
